package com.epam.bank;

import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class Spectator {
	private static int count = 0;
	private final int id = ++count;
	private static Logger logger = Logger.getLogger(Spectator.class);

	public synchronized void bringCash(Cashier cashier) {
		try {
			TimeUnit.MILLISECONDS.sleep(200);
			if (cashier.getAmountEUR() < 250) {
				cashier.incAmountEUR(500);
				logger.info("Spectator " + id + " brang 500 Eur to the "
						+ "cashier "+cashier.getId()+": "+cashier
						.getAmountEUR()+" Eur left");
			}
			if (cashier.getAmountUSD() < 250) {
				cashier.incAmountUSD(500);
				logger.info("Spectator " + id + " brang $500 to the "
						+ "cashier "+cashier.getId()+": $"+cashier
						.getAmountUSD()+" left");
			}
		} catch (InterruptedException e) {
			logger.error("Spectator interrupted!");
		}
	}

	public int getId() {
		return id;
	}
}
